import tools from '../utils/tools';

@tools
class HeaderSearch {
    constructor() {
        this.name = 'HeaderSearch';
        this.$searchForm = $('#J_searchForm');
        this.$searchInput = $('#J_keyword');
        this.$searchBtn = $('.J_searchBtn');
    }
    init() {
        this.bindEvent();
    }
    bindEvent() {
        this.$searchBtn.on('click', $.proxy(this.searchBtnHandler, this))
    }

    searchBtnHandler(e) {
        let searchInputValue = HeaderSearch.trimSpace(this.$searchInput.val()),
            length = searchInputValue.length;
        if (length > 0) {
            window.open(this.$searchForm.attr('action') + searchInputValue );
        }
    }
}

export default HeaderSearch;